package Units;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XmlCreatureImport {
	private static String name;
	private static int nameTextID;
	private static int baseSpeed;
	
	
	//public XmlCreatureImport() {
	public static void main(String argv[]) {
		try {
			File file = new File("data/imp.xml");
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			Document doc = db.parse(file);
			doc.getDocumentElement().normalize();
			System.out.println("Root element " + doc.getDocumentElement().getNodeName());
			NodeList nodeLst = doc.getElementsByTagName("Creature");
			System.out.println("Information of all Creatures");
	
			for (int s = 0; s < nodeLst.getLength(); s++) {
				Node fstNode = nodeLst.item(s);
				
				if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
					Element fstElmnt = (Element) fstNode;
					
					/*NodeList nameEleLst = fstElmnt.getElementsByTagName("Name");
					name = nameEleLst.item(0).getChildNodes().item(0).getNodeValue();
					System.out.println("Name : "  + name);
					
					NodeList nameTxtIDEleLst = fstElmnt.getElementsByTagName("NameTextID");
					nameTextID = Integer.valueOf(nameTxtIDEleLst.item(0).getChildNodes().item(0).getNodeValue()).intValue();
					System.out.println("NameTextID : " +  nameTextID);
					
					NodeList baseSpdEleLst = fstElmnt.getElementsByTagName("BaseSpeed");
					baseSpeed = Integer.valueOf(baseSpdEleLst.item(0).getChildNodes().item(0).getNodeValue()).intValue();
					System.out.println("BaseSpeed : " +  baseSpeed);*/
				
					NodeList nl = fstElmnt.getFirstChild().getChildNodes();
					//for (int i = 0; i < nl.getLength(); i++) {
						Node n = nl.item(0);
						System.out.println(n.getNodeName());
						System.out.println(n.getNodeValue());
						
					//}
				}
				/*
				<Health>75</Health>
				<Strength>5</Strength>
				<Armour>5</Armour>
				<Dexterity>14</Dexterity>
				<Fear>255</Fear>
				<Defence>5</Defence>
				<BaseSpeed>96</BaseSpeed>
				*/
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
